
// import oimo.m.Vec3;
// import oimo.m.M;

import { Vec3 } from "../../../common/Vec3";
import { M } from "../../../common/M";

/**
 * The row of a Jacobian matrix.
 */
export class JacobianRow {
	lin1: Vec3;
	lin2: Vec3;
	ang1: Vec3;
	ang2: Vec3;

	static BIT_LINEAR_SET: number = 1;
	static BIT_ANGULAR_SET: number = 2;
	flag: number; // sparsity flag

	constructor() {
		this.lin1 = new Vec3();
		this.lin2 = new Vec3();
		this.ang1 = new Vec3();
		this.ang2 = new Vec3();
		this.flag = 0;
	}


	public clear(): void {
		this.lin1.zero();
		this.lin2.zero();
		this.ang1.zero();
		this.ang2.zero();
	}

	public updateSparsity(): void {
		this.flag = 0;
		if (!M.vec3_isZero(this.lin1) || !M.vec3_isZero(this.lin2)) {
			this.flag |= JacobianRow.BIT_LINEAR_SET;
		}
		if (!M.vec3_isZero(this.ang1) || !M.vec3_isZero(this.ang2)) {
			this.flag |= JacobianRow.BIT_ANGULAR_SET;
		}
	}


	public isLinearSet(): boolean {
		return (this.flag & JacobianRow.BIT_LINEAR_SET) != 0;
	}


	public isAngularSet(): boolean {
		return (this.flag & JacobianRow.BIT_ANGULAR_SET) != 0;
	}

}
